package com.sx.pipeline.ui.linepipe

import android.app.Application
import android.text.TextUtils
import com.blankj.utilcode.util.ThreadUtils
import com.blankj.utilcode.util.ToastUtils
import com.sx.mvvmlibs.event.SingleLiveEvent
import com.sx.mvvmlibs.utils.Logs
import com.sx.pipeline.app.model.CYBaseViewModel
import com.sx.pipeline.repos.http.res.Ipage
import com.sx.pipeline.repos.http.res.TerritoryVO
import com.sx.pipeline.repos.local.db.table.FileNodesBeanDO
import com.sx.pipeline.repos.local.db.table.PipeFileBeanDO
import com.sx.pipeline.utils.kml.FileParseBean
import com.sx.pipeline.utils.kml.KmlHelper
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.functions.Consumer
import io.reactivex.rxjava3.schedulers.Schedulers
import java.io.File
import java.nio.channels.Pipe

/**
 * @Author: YY
 * @Date: 2022/8/10
 * @Desc: TODO
 */
class LinePipeVM(app: Application): CYBaseViewModel(app) {

    /**
     * 获取 Tab标题
     */
    fun getTerritoryTypeList(): List<String> {
        val tabs = mutableListOf<String>()
        tabs.add("KML文件")
        tabs.add("DXF文件")
        return tabs
    }

    val territoryListEvent: SingleLiveEvent<List<PipeFileBeanDO>> = SingleLiveEvent()

    fun getFileBeanList(type: Int) {
        addSubscribe(
            mModel.getFileBeanAll(type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(Consumer {
                    Logs.d("getFileBeanAll Success ${it.size}")
                    territoryListEvent.postValue(it)
                })
        )
    }

    val deleteTerritoryEvent: SingleLiveEvent<Void> = SingleLiveEvent()

    fun deleteFileBean(fileBeanDO: PipeFileBeanDO) {
        addSubscribe(
            mModel.deleteFileBean(fileBeanDO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(Consumer {
                    ToastUtils.showShort("删除成功")
                    deleteTerritoryEvent.call()
                })
        )
    }
}